這裡我預計要寫做出選擇和決定時會用的語法
using System;
namespace HelloWorld2
{
class Program
{
public static void Main(string[] args)
{
string userName = "";
int userAge = 0;
int currentYear = 0;
Console.WriteLine("請輸入您的名字:");
userName = Console.ReadLine();
Console.WriteLine("輸入您的年齡:");
userAge = Convert.ToInt32(Console.ReadLine());
if(userAge <0 || userAge > 100)
{
Console.WriteLine("不可能年齡");
Console.WriteLine("必須要在1-100之間");
}
else if(userAge < 18)
{
Console.WriteLine("抱歉您的年齡太小");
}
else if (userAge < 21)
{
Console.WriteLine("需要家長同意");
}
else
{
Console.WriteLine("恭喜您可以登入");
}
}
}
}
break 就是跳出
using System;
namespace HelloWorld2
{
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("輸入您的等級:");
string userGrade = Console.ReadLine();
switch (userGrade)
{
case "A":
Console.WriteLine("優秀");
break;
case "B":
Console.WriteLine("B級");
break;
case "C":
Console.WriteLine("C級");
break;
default:
Console.WriteLine("Fail");
break;
}
}
}
}
這裡是每一行i+1
顯示0-4
using System;
namespace HelloWorld2
{
class Program
{
public static void Main(string[] args)
{
for (int i = 0; i < 5; i++)
{
Console.WriteLine(i);
}
}
}
}
顯示[]裡面的數字
using System;
namespace HelloWorld2
{
class Program
{
public static void Main(string[] args)
{
int[] myNumber = { 10, 20, 30,40,50 };
for (int i = 0; i < myNumber.Length; i++)
{
Console.WriteLine(myNumber[i]);
}
}
}
}
using System;
namespace HelloWorld2
{
class Program
{
public static void Main(string[] args)
{
char[] message = { 'H', 'e', 'l', 'l', 'o'};
foreach (char i in message) { Console.WriteLine(i);
}
}
}
}
用--來-1
using System;
namespace HelloWorld2
{
class Program
{
public static void Main(string[] args)
{
int counter = 5;
while (counter > 0) { Console.WriteLine("Counter ={0}",counter);
counter--;
}
}
}
}
其實這些都是我原本迷路的地方可能要分兩篇
DEAR ALL 我們明天見